package cn.kgc.controller;

import cn.kgc.bean.dto.CollectionDto;
import cn.kgc.bean.pojo.CCaseCollection;
import cn.kgc.common.Result;
import cn.kgc.service.ConllectionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/collection")
public class CollectionContoller {
    @Resource
    private ConllectionService conllectionService;

    @GetMapping("/getCollection")
    public Result getCollection(@RequestParam Integer userId,
                                 @RequestParam int pageNum,
                                 @RequestParam int pageSize,
                                 @RequestParam(required = false) String caseName,
                                 @RequestParam(required = false) String num,
                                 @RequestParam(required = false) String undertaker){
        PageHelper.startPage(pageNum,pageSize);
        List<CollectionDto> list = conllectionService.getConllection(userId,caseName,num,undertaker);
        PageInfo<CollectionDto> pageInfo = new PageInfo<>(list);
        if(pageInfo != null){
            return Result.success(pageInfo);
        }else {
            return Result.error();
        }
    }
    @GetMapping("/deleteInfo")
    public Result deleteInfo(@RequestParam int userid,
                             @RequestParam int caseid){
      int count = conllectionService.deleteInfo(userid,caseid);
        if (count>0) {
            return Result.success();
        }else {
            return Result.error();
        }
    }

    @PostMapping("/addInfo")
    public Result addInfo(@RequestBody CCaseCollection cCaseCollection){
        int count = conllectionService.addInfo(cCaseCollection);
        if (count>0) {
            return Result.success();
        }else {
            return Result.error();
        }
    }
}
